package jdbc01;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import static java.lang.Class.forName;

public class JDBCDemo01 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://127.0.0.1:3306/test?useSSL=false";
        Connection conn = DriverManager.getConnection(url, "root", "123456");
        System.out.println(conn);
        Statement state = conn.createStatement();//创建一个发送sql语句的平台
        ResultSet resultSet = state.executeQuery("SELECT * FROM product");//发送指定的sql语言
        //获取sql的释放结果
        while (resultSet.next()) {
            System.out.println(resultSet.getInt("pid")+" "+resultSet.getString("pname")+" "+
                     resultSet.getDouble("price"));
        }
        //释放资源
        conn.close();
        state.close();
    }
}
